package com.lwj.mallchat.common.user.service.impl;

import com.lwj.mallchat.common.user.dao.UserRoleDao;
import com.lwj.mallchat.common.user.domain.entity.UserRole;
import com.lwj.mallchat.common.user.domain.enums.RoleEnum;
import com.lwj.mallchat.common.user.service.RoleService;
import com.lwj.mallchat.common.user.service.cache.UserCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @author lwj
 * @ClassName RoleServiceImpl
 * @date 2024/10/24 14:30
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private UserRoleDao userRoleDao;

    @Autowired
    private UserCache userCache;

    @Override
    public boolean hasPower(Long uid, RoleEnum roleEnum) {
        Set<Long> roleSet = userCache.getRoleSet(uid);
        return roleSet.contains(roleEnum.getId());
    }

    private boolean isAdmin(Set<Long> roleSet) {
        return roleSet.contains(RoleEnum.ADMIN);
    }
}
